<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
 
      <el-form-item label="联系姓名" prop="contactName">
        <el-input
          v-model="queryParams.contactName"
          placeholder="请输入联系人姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系方式" prop="contactNumber">
        <el-input
          v-model="queryParams.contactNumber"
          placeholder="请输入联系方式"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学历" prop="educationLevel">
        <el-select v-model="queryParams.educationLevel" placeholder="请选择学历" clearable>
          <el-option
            v-for="dict in dict.type.education_level"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="职称" prop="jobTitle">
        <el-input
          v-model="queryParams.jobTitle"
          placeholder="请输入职称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
     
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['zzw:booking:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="bookingList" @selection-change="handleSelectionChange" :show-overflow-tooltip="true">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="唯一标识" align="center" prop="id" />
      <el-table-column label="单位" align="center" prop="company" show-overflow-tooltip />
      <el-table-column label="联系人姓名" align="center" prop="contactName" />
      <el-table-column label="联系方式" align="center" prop="contactNumber" />
      <el-table-column label="学历" align="center" prop="educationLevel"  show-overflow-tooltip/>
      <el-table-column label="职称" align="center" prop="jobTitle" />
      <el-table-column label="专业" align="center" prop="major"  show-overflow-tooltip />
      <el-table-column label="研究方向" align="center" prop="researchDirection"  show-overflow-tooltip  />
      <el-table-column label="期刊级别" align="center" prop="journalLevel"  show-overflow-tooltip/>
      <el-table-column label="所在单位认可的期刊" align="center" prop="journalRecognized"  show-overflow-tooltip  />
      <el-table-column label="期刊发表时间要求" align="center" prop="publicationTimeRequired" width="180"  show-overflow-tooltip />
      <el-table-column label="是否需要著作" align="center" prop="isWritings"/>
      <el-table-column label="论文用途" align="center" prop="thesisUse"  show-overflow-tooltip />
      <el-table-column label="论文要求" align="center" prop="thesisRequire"  show-overflow-tooltip  />
      <el-table-column label="是否有论文" align="center" prop="isThesis" />
      <el-table-column label="刊物要求" align="center" prop="publicationRequire"  show-overflow-tooltip  />
      <el-table-column label="创建时间" align="center" prop="createTime"  width="100" />
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改预约咨询对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="联系人姓名" prop="contactName">
          <el-input v-model="form.contactName" placeholder="请输入联系人姓名" />
        </el-form-item>
        <el-form-item label="联系方式" prop="contactNumber">
          <el-input v-model="form.contactNumber" placeholder="请输入联系方式" />
        </el-form-item>
        <el-form-item label="学历" prop="educationLevel">
          <el-select v-model="form.educationLevel" placeholder="请选择学历">
            <el-option
              v-for="dict in dict.type.education_level"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="职称" prop="jobTitle">
          <el-input v-model="form.jobTitle" placeholder="请输入职称" />
        </el-form-item>
        <el-form-item label="专业" prop="major">
          <el-input v-model="form.major" placeholder="请输入专业" />
        </el-form-item>
        <el-form-item label="研究方向" prop="researchDirection">
          <el-input v-model="form.researchDirection" placeholder="请输入研究方向" />
        </el-form-item>
        <el-form-item label="期刊级别" prop="journalLevel">
          <el-input v-model="form.journalLevel" placeholder="请输入期刊级别" />
        </el-form-item>
        <el-form-item label="所在单位认可的期刊" prop="journalRecognized">
          <el-input v-model="form.journalRecognized" placeholder="请输入所在单位认可的期刊" />
        </el-form-item>
        <el-form-item label="期刊发表时间要求" prop="publicationTimeRequired">
          <el-date-picker clearable
            v-model="form.publicationTimeRequired"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择期刊发表时间要求">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="是否需要著作" prop="isWritings">
          <el-select v-model="form.isWritings" placeholder="请选择是否需要著作">
            <el-option
              v-for="dict in dict.type.sys_show_hide"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="论文用途" prop="thesisUse">
          <el-input v-model="form.thesisUse" placeholder="请输入论文用途" />
        </el-form-item>
        <el-form-item label="论文要求" prop="thesisRequire">
          <el-input v-model="form.thesisRequire" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="是否有论文" prop="isThesis">
          <el-input v-model="form.isThesis" placeholder="请输入是否有论文" />
        </el-form-item>
        <el-form-item label="刊物要求" prop="publicationRequire">
          <el-input v-model="form.publicationRequire" placeholder="请输入刊物要求" />
        </el-form-item>
       
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listBooking, getBooking, delBooking, addBooking, updateBooking } from "@/api/zzw/booking";

export default {
  name: "Booking",
  dicts: ['education_level', 'sys_show_hide'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 预约咨询表格数据
      bookingList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        openid: null,
        contactName: null,
        contactNumber: null,
        educationLevel: null,
        jobTitle: null,
        major: null,
        researchDirection: null,
        journalLevel: null,
        journalRecognized: null,
        publicationTimeRequired: null,
        isWritings: null,
        thesisUse: null,
        thesisRequire: null,
        isThesis: null,
        publicationRequire: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        contactName: [
          { required: true, message: "联系人姓名不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询预约咨询列表 */
    getList() {
      this.loading = true;
      listBooking(this.queryParams).then(response => {
        this.bookingList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        contactName: null,
        contactNumber: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加预约咨询";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getBooking(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改预约咨询";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateBooking(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addBooking(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除预约咨询编号为"' + ids + '"的数据项？').then(function() {
        return delBooking(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('zzw/booking/export', {
        ...this.queryParams
      }, `booking_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
